Test Shader compilation with WEBMIN flag#1638
Open
CedricGuillemet wants to merge 14 commits into
Open
Conversation
…nto TestShaderCompilation # Conflicts: # Dependencies/CMakeLists.txt
…nto TestShaderCompilation # Conflicts: # Apps/UnitTests/CMakeLists.txt
…nto TestShaderCompilation
…nto TestShaderCompilation # Conflicts: # Apps/UnitTests/CMakeLists.txt
…raversers. UniformTypeChangeTraverser and MoveNonSamplerUniformsIntoStruct only excluded samplers and matrices, so they happily visited the symbols representing whole `layout(std140) uniform` blocks (EbtBlock) and `uniform Foo foo;` struct instances (EbtStruct), rewriting them to vec4. Once that happened, spirv-cross emitted unnamed placeholder uniforms (e.g. `uniform vec4 _1195;`) and the matrix multiplies collapsed to scalar nonsense, then bgfx asserted on the empty uniform name (`Identifier can't be empty.`). Restrict both traversers to scalar/vector basic types (Float/Int/Uint/ Bool) so blocks and structs are left intact. Also throw early in CollectNonSamplerUniforms if a uniform name is empty, so any future regression surfaces in the compiler instead of as a deep bgfx assert. Add a TODO in CMakeLists.txt to point SPIRV-Cross back to the upstream BabylonJS fork once the corresponding PR there is merged.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a comprehensive shader cross-compilation unit test and tightens shader AST traversers to avoid incorrectly rewriting UBO blocks and struct uniforms, preventing empty/placeholder uniform identifiers from reaching bgfx.
Changes:
- Restrict uniform traversers to basic scalar/vector types to avoid visiting
EbtBlock/EbtStructuniforms. - Add a UnitTests scenario that compiles a large WebGL2 GLSL shader to exercise SPIRV-Cross with the WEBMIN flag.
- Update the fetched SPIRV-Cross dependency to a specific fork/commit and add an early compiler-side guard for empty uniform names.
Reviewed changes
Copilot reviewed 7 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| Plugins/ShaderCompiler/Source/ShaderCompilerTraversers.cpp | Limits traversers to avoid rewriting UBO blocks/struct uniforms. |
| Plugins/ShaderCompiler/Source/ShaderCompilerCommon.cpp | Adds early failure when a reflected uniform name is empty. |
| CMakeLists.txt | Changes SPIRV-Cross FetchContent repository/commit. |
| Apps/UnitTests/Source/Tests.Shaders.Cross.cpp | Adds a new runtime-backed shader compilation unit test. |
| Apps/UnitTests/JavaScript/webpack.config.js | Adds a new webpack entry for the shader cross test. |
| Apps/UnitTests/JavaScript/src/tests.shaders.cross.ts | New “comprehensive GLSL” test script. |
| Apps/UnitTests/JavaScript/dist/tests.shaders.cross.js | Built webpack output for the new test script. |
| Apps/UnitTests/JavaScript/dist/tests.shaderCache.basicScene.js | Updated built output (webpack bootstrap changes). |
| Apps/UnitTests/CMakeLists.txt | Includes new JS asset and C++ test source in UnitTests target. |
Comment on lines
+312
to
320
| // We only care about loose scalar/vector uniforms. Excluding matrices, samplers, | ||
| // UBO blocks (EbtBlock) and uniform struct instances (EbtStruct) prevents the | ||
| // traverser from rewriting whole blocks/structs to vec4, which destroys their | ||
| // member layout and member names. | ||
| const auto basic = type.getBasicType(); | ||
| if (type.getQualifier().isUniformOrBuffer() | ||
| && !type.isMatrix() | ||
| && (basic == EbtFloat || basic == EbtInt || basic == EbtUint || basic == EbtBool)) | ||
| { |
bkaradzic-microsoft
approved these changes
May 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Use a generated shader to check no mandatory glsl function missing in spirv-cross when using WEBMIN flag.
BabylonJS/SPIRV-Cross#10
Fix
UniformTypeChangeTraverserandMoveNonSamplerUniformsIntoStructwere also visiting wholelayout(std140) uniformblocks (EbtBlock) anduniform Foo foo;struct instances (EbtStruct) and rewriting them tovec4, producing unnamed placeholder uniforms in the spirv-cross output and aIdentifier can't be empty.assert in bgfx. Both traversers are now restricted to scalar/vector basic types (Float/Int/Uint/Bool).CollectNonSamplerUniformsalso throws early if a uniform name is empty so future regressions surface in the compiler instead of deep in bgfx.